package com.todo.pro.res;

import java.io.Serializable;

import com.todo.pro.res.enums.ErrCodeEnum;

public class JsonResult<T> implements Serializable {
	private static final long serialVersionUID = -4699713095477151086L;

	/**
	 * 信息
	 */
	private String message;
	/**
	 * 请求结果编码
	 */
	private int code;
	/**
	 * 是否成功
	 */
	private boolean success;
	/**
	 * 数据
	 */
	private T data;
	/**
	 * 数据条数
	 */
	private int count;

	public Object getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public JsonResult() {
		super();
	}

	public JsonResult(int count, T data) {
		this.code = 0;
		this.success = true;
		this.message = "请求成功";
		this.data = data;
		this.count = count;
	}

	public JsonResult(T data) {
		this.success = true;
		this.code = ErrCodeEnum.SUC.code;
		this.message = "请求成功";
		this.data = data;
	}

	public JsonResult(boolean success, String message) {
		this.message = message;
		this.success = success;
		this.code = success ? ErrCodeEnum.SUC.code : ErrCodeEnum.FAIL.code;
	}
}